require "rubygems"
require "watir-webdriver"

$host = "http://dev.nodoinmobiliario.com/"
$browser = Watir::Browser.new :chrome

$cred = {
    "email" => "demo@demo.com",
    "pwd" => "12345678",
    "registerUser" => {
        'name' => 'demo2',  
        'email' => 'demo2@demo.com',  
        'pwd' => '123456',  
        'pwd2' => '123456',  
        'zip' => '2000'  
     } 
}
#INSERT INTO `accounts` (`id`, `username`, `email`, `password`, `zip`, `confirmed`, `recovery`, `created`, `updated`) VALUES
#(1, 'demo', 'demo@demo.com', '25d55ad283aa400af464c76d713c07ad', '2000', 0, '', '2012-01-13 00:00:00', '0000-00-00 00:00:00');


def go webPage
    $browser.goto webPage
end

def testHomePage
    go $host
end

def testLogin
    go $host
    $browser.text_field(:id, "email").set($cred["email"])
    $browser.text_field(:id, "pwd").set($cred["pwd"])
#    $browser.hidden(:name, "csrf").set("xxxx")
    $browser.button(:id, "signin").click
end

def testRegistration
    go $host+'account/register'
    $browser.text_field(:id, "nombre").set($cred["registerUser"]["name"])
    $browser.text_field(:id, "email").set($cred["registerUser"]["email"])
    $browser.text_field(:id, "pwd").set($cred["registerUser"]["pwd"])
    $browser.text_field(:id, "pwdconfirm").set($cred["registerUser"]["pwd2"])
    $browser.text_field(:id, "codPostal").set($cred["registerUser"]["zip"])
    $browser.button(:id, "signup").click
end

def closeBrowser
    puts "press a key to close the browser"
    STDIN.gets
    $browser.close
end

#Tests to execute
#testHomePage
#testLogin
testRegistration
closeBrowser
